// 標記點擊事件
private void setUpMapIfNeeded() {
if (mMap == null) {
mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
if (mMap != null) {
//setUpMap();
processController();
}
}
}
// ConnectionCallbacks
@Override
public void onConnected(Bundle bundle) {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
LocationServices.FusedLocationApi.requestLocationUpdates(
googleApiClient, locationRequest, (com.google.android.gms.location.LocationListener) MapsActivity.this);
}
// 已經連線到Google Services
// 啟動位置更新服務
// 位置資訊更新的時候,應用程式會自動呼叫LocationListener.onLocationChanged
// ConnectionCallbacks
@Override
public void onConnectionSuspended(int i) {
}
// OnConnectionFailedListener
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
int errorCode = connectionResult.getErrorCode();
if (errorCode == ConnectionResult.SERVICE_MISSING) {
Toast.makeText(this, R.string.google_play_service_missing,
Toast.LENGTH_LONG).show();
}
}